package ex.strategy.atomix_tx;

/**
 * Created with IntelliJ IDEA.
 * User: sababa
 * Date: 08.02.13
 * Time: 13:54
 * To change this template use File | Settings | File Templates.
 */
public class YEasyManager implements EasyManager {
    public boolean transfer(EasyAccount[] accounts, int[] money) {
        int k = 0;
        try {
            for (k = 0; k < accounts.length; k++) {
                while (true) {
                    try {
                        accounts[k].change(money[k]);
                        break;
                    } catch (TryAgainEx e) {
                        // NOP
                    }
                }
            }
        } catch (ZedDeadBabyEx e) {

            try {
                for (int i = 0; i < k; i++) {
                    while (true) {
                        try {
                            accounts[i].change(-money[i]);
                            break;
                        } catch (TryAgainEx e1) {
                            // NOP
                        }
                    }
                }
            } catch (ZedDeadBabyEx z) {
            }
            return false;
        }
        return true;
    }
}
